﻿using Business;
using Model;
using Public;
using Public.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using wochu.DPS.API.Infrastructure;

namespace wochu.DPS.API.Controllers
{
    public class OffShelvesOrderController : ApiController
    {
        private static OffShelvesOrderBll _NewInstance = new OffShelvesOrderBll();

        public static OffShelvesOrderBll NewInstance
        {
            get
            {
                if (_NewInstance == null)
                {
                    _NewInstance = new OffShelvesOrderBll();
                }

                return _NewInstance;
            }
        }
        [HttpPost]
        public HttpResponseMessage SetOffMiddleShelves(string userID, List<pft_middle_inventoryTMP> list)
        {
            string message = "";
            SysSetting sett = new SysSetting();
            if (string.IsNullOrEmpty(userID) || list == null || list.Count <= 0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "参数有误";
                return ResultsExtensions.GetFailJson(sett);
            }
            List<pft_middle_goodsinventory> listPost = new List<pft_middle_goodsinventory>();
            foreach (var item in list)
            {
                listPost.Add(new pft_middle_goodsinventory { CREATERID = 0, GOODSID = item.GOODSID, QTY = item.QTYEXCE, STATUS = 1 });
            }
            if (NewInstance.SetOffMiddleShelves(userID, out message, listPost))
                return ResultsExtensions.GetSuccessJson(true);
            else
            {
                SysSetting syserr = new SysSetting() { Key = "0", Value = message };
                return ResultsExtensions.GetFailJson(syserr);
            }
        }

        [HttpGet]
        public HttpResponseMessage GetMiddleGoodsInfoByCode(string GoodsCode)
        {
            SysSetting sett = new SysSetting();
            if (string.IsNullOrEmpty(GoodsCode))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "参数有误";
                return ResultsExtensions.GetFailJson(sett);
            }
            pft_middle_inventoryTMP _result = NewInstance.GetMiddleGoodsInfoByBarCode(GoodsCode);
            if (_result == null)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "无编码：" + GoodsCode + " 的中间仓库存商品信息";
                return ResultsExtensions.GetFailJson(sett);
            }
            else
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
        }

        [HttpGet]
        public HttpResponseMessage GetMiddleGoodsInfoByName(string GoodsName)
        {
            SysSetting sett = new SysSetting();
            if (string.IsNullOrEmpty(GoodsName))
            {
                sett.Key = Consts.strFalse;
                sett.Value = "参数有误";
                return ResultsExtensions.GetFailJson(sett);
            }
            List<pft_middle_inventoryTMP> _result = NewInstance.GetMiddleGoodsInfoByBarName(GoodsName);
            if (_result == null || _result.Count<=0)
            {
                sett.Key = Consts.strFalse;
                sett.Value = "无商品：" + GoodsName + " 的库存商品信息";
                return ResultsExtensions.GetFailJson(sett);
            }
            else
            {
                return ResultsExtensions.GetSuccessJson(_result);
            }
        }
    }
}
